package cn.bigway.app.weavingdesigner.action;

import cn.bigway.app.weavingdesigner.action.newdoc.WdNewDocDialog;
import cn.bigway.app.weavingdesigner.log.WdLog;
import cn.bigway.app.weavingdesigner.swing.WdButton;
import cn.bigway.app.weavingdesigner.type.WdMenuItemType;
import cn.bigway.app.weavingdesigner.util.WdBaseFactory;

final public class WdActionFactory extends
		WdBaseFactory<WdAction, WdMenuItemType> {
	private static final WdActionFactory instance = new WdActionFactory();

	private WdActionFactory() {
		//
	}

	public static WdActionFactory getInstance() {
		return instance;
	}

	public WdButton createButton(WdMenuItemType type) {
		WdButton button = new WdButton();
		button.setAction(WdActionFactory.getInstance().get(type));
		button.setText("");
		return button;
	}

	@SuppressWarnings("serial")
	@Override
	protected WdAction create(WdMenuItemType type) {
		switch (type) {
		case EMIT_ABOUT:
			return new WdDialogAction<WdAboutDialog>(type) {
				@Override
				protected WdAboutDialog createDialog() {
					return new WdAboutDialog();
				}
			};
		case EMIT_CLOSE:
			break;
		case EMIT_CLOSE_ALL:
			break;
		case EMIT_EXIT:
			break;
		case EMIT_NEW:
			return new WdDialogAction<WdNewDocDialog>(type) {
				@Override
				protected WdNewDocDialog createDialog() {
					return new WdNewDocDialog();
				}
			};
		case EMIT_OPEN:
			break;
		case EMIT_REDO:
			break;
		case EMIT_SAVE:
			break;
		case EMIT_SAVE_ALL:
			break;
		case EMIT_SAVE_AS:
			break;
		case EMIT_SHOW_VEIW:
			break;
		case EMIT_UNDO:
			break;
		case EMIT_IMPORT_IMAGE:
			return new WdDialogAction<WdImportImageDialog>(type) {
				@Override
				protected WdImportImageDialog createDialog() {
					return new WdImportImageDialog();
				}
			};
		}

		WdLog.error("No action for " + type.name());
		return null;
	}
}
